package com.basics.common.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * 阿里云短信/手机验证码
 * @author: wangwei
 * @Date: 2021/11/1 16:37
 * @Description:
 */
public class SmsWhUtil {
    private static String accessKeyId = "LTAI5tBsYXKvF6tAauTyntm1";
    private static String accessKeySecret = "EqGTfXeoFRu7TPYsvoh1B11nRifIPD";

    public static String sendSms(String phone, String code) {
            DefaultProfile profile = DefaultProfile.getProfile("cn-zhangjiakou", accessKeyId, accessKeySecret);
            IAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.setSysMethod(MethodType.POST);
            request.setSysDomain("dysmsapi.aliyuncs.com");
            request.setSysVersion("2017-05-25");
            request.setSysAction("SendSms");
            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", phone);
            request.putQueryParameter("SignName", "礼帽信息");
            request.putQueryParameter("TemplateCode", "SMS_251135736");
            request.putQueryParameter("TemplateParam", "{'code':" + code + "}");

            try {
                CommonResponse response = client.getCommonResponse(request);
                return response.getData();
            } catch (ServerException var6) {
                var6.printStackTrace();
            } catch (ClientException var7) {
                var7.printStackTrace();
            }
            return null;
    }

    public static void main(String[] args) {
        sendSms("15102748056", "123456");
    }
}
